/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.daoImpl;

import br.com.deployment.dao.AnexoDAO;
import br.com.deployment.entities.Anexo;
import br.com.deployment.entities.Issues;
import br.com.deployment.entities.QuestionnaireResponse;
import br.com.deployment.entities.Response;
import br.com.deployment.genericdao.GenericDAO;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author ely
 */
@Stateless
@LocalBean
public class AnexoDAOImpl extends GenericDAO<Anexo> implements AnexoDAO {

    public AnexoDAOImpl() {
        super(Anexo.class);
    }

    @Override
    public List<Anexo> findAnexo(Anexo anexo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Anexo> findReponseAnexo(Response response) {
        String sql = "SELECT a FROM Response r JOIN r.anexo a WHERE"
                + " r.id = :id";
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", response.getId());
        return (List<Anexo>) query.getResultList();
    }

    public Anexo findUUID(Long id, String UUID) {
        String sql = "SELECT a FROM Anexo a WHERE"
                + " a.cod = :id and a.UUID = :uuid order by a.id desc";
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", id);
        query.setParameter("uuid", UUID);
        return (Anexo) query.getResultList().get(0);
    }
    
    public List<Anexo> findQuestionnaireReponseAnexo(QuestionnaireResponse questionnaireResponse){
        
         String sql = "SELECT a FROM QuestionnaireResponse qr JOIN qr.anexo a WHERE"
                + " qr.id = :id";
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", questionnaireResponse.getId());
        return (List<Anexo>) query.getResultList();
        
    }
}
